/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pb138.jprvyd;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 *
 * @author tom
 */
public class Invoice {
    private Long id;
    private int number;
    private Contact contact;
    private List<Item> items = new ArrayList<Item>();
    private Date date;
    private Date endDate;
    private int variableSymbol;
    private PaymentMethod paymentMethod;

    public Invoice() {
    }

    public Contact getContact() {
        return contact;
    }

    public void setContact(Contact contact) {
        this.contact = contact;
    }

    public Date getDate() {
        if(date == null){
            return null;
        }
        
        return (Date)date.clone();
    }

    public void setDate(Date date) {
        if(date == null){
            return;
        }
        
        this.date = new Date(date.getTime());
    }

    public Date getEndDate() {
        if(endDate == null){
            return null;
        }
        
        return (Date)endDate.clone();
    }

    public void setEndDate(Date endDate) {
        if(endDate == null){
            return;
        }
        
        this.endDate = new Date(endDate.getTime());       
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public List<Item> getItems() {
        return Collections.unmodifiableList(items);
    }

    public void setItems(List<Item> items) {
        if(items == null){
            return;
        }
        
        this.items = new ArrayList<Item>();
        this.items.addAll(items);
    }

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }

    public PaymentMethod getPaymentMethod() {
        return paymentMethod;
    }

    public void setPaymentMethod(PaymentMethod paymentMethod) {
        this.paymentMethod = paymentMethod;
    }

    public int getVariableSymbol() {
        return variableSymbol;
    }

    public void setVariableSymbol(int variableSymbol) {
        this.variableSymbol = variableSymbol;
    }

    public int getPrice() {
        int price = 0;
        for (Item item : items) {
            price += item.getUnitPrice() * item.getQuantity();
        }
        return price;
    }
    
}
